package cn.chochy.my.dao.impl;

import cn.chochy.my.dao.BaseDao;
import cn.chochy.my.util.ClassGenerics;


import java.util.List;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author MLeo
 * @param <T>
 */
public  class BaseDaoImpl<T>  implements BaseDao<T> {
    @Autowired
    private SqlSession sqlSession;

    private String entityClassName;

    @Autowired
    public void initialize() throws Exception{
        System.out.println("&&&&&&&&&&&&&&&"+entityClassName+"&&&&&&&&&&&&&&");
        entityClassName = ClassGenerics.fatherClassGenerics(getClass());
        System.out.println("&&&&&&&&&&&&&&&"+entityClassName+"&&&&&&&&&&&&&&");
        
    }

    @Override
    public List<T> queryList(T t) {
        return this.sqlSession.selectList(entityClassName+".queryList", t);
    }

    @Override
    public T queryById(Integer id) {
        return this.sqlSession.selectOne(entityClassName + ".queryById", id);
    }

    @Override
    public Integer updateById(T t) {
        return this.sqlSession.update(entityClassName + ".updateById", t);
    }

    @Override
    public Integer insertObject(T t) {
        return this.sqlSession.insert(entityClassName + ".insertObject", t);
    }

    @Override
    public Integer deleteById(T t) {
        return this.sqlSession.delete(entityClassName + "deleteById", t);
    }

    public SqlSession getSqlSession() {
        return sqlSession;
    }

    public void setSqlSession(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
        System.out.println("&&&&&&&&&&&&&&&&&&"+sqlSession+"&&&&&&&&&&&&&&&&&&&&&");
    }

    

}
